import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import nodeGlobals from 'rollup-plugin-node-globals';
import minify from 'rollup-plugin-babel-minify';
import builtins from './nodeos/node/src/builtins/index.js';
import typescript from 'rollup-plugin-typescript2';
import babel from '@rollup/plugin-babel';
function onwarn(warning) {
  if (warning.code !== 'CIRCULAR_DEPENDENCY') {
      console.error(`(!) ${warning.message}`);
  }
}

const plugins = [
  typescript({
    // tsconfigOverride: {
    //   compilerOptions: {
    //     //strict: false
    //     //tsconfig: './nodeos/node/tsconfig.json',
    //     alwaysStrict: false,
    //     forceConsistentCasingInFileNames: true,
    //     noImplicitUseStrict: true,
    //     module: "ES2015",
    //     noEmitOnError: true,
    //     noImplicitAny: true,
    //     noImplicitReturns: true,
    //     noImplicitThis: true,
    //     skipLibCheck: true,
    //     sourceMap: false,
    //     strict: true,
    //     target: "ES5", // max. for which with-statement in eval works
    //     types: ["node"],
    //     lib: ["ES2017", "webworker"],
    //     newLine: "LF",
    //     ignoreDeprecations: "5.0"
    //   }
    // }

  }),
  // babel({
  //   babelrc: false,
  //   presets: [['@babel/preset-env', { modules: false, loose: true }]],
  //   plugins: [['@babel/plugin-proposal-class-properties', { loose: true }]],
  //   exclude: 'node_modules/**',
  // }),
  commonjs(),
  builtins(),
  nodeResolve({
    preferBuiltins: false,
    mainFields: ['browser', 'module', 'main'],
  }),
  nodeGlobals(),
  json(),
];

if (process.env.BUILD) {
  plugins.push(minify());
}
export default {
  onwarn,
  treeshake: false,
  input: './nodeos/node/src/app.ts',
  output: {
    strict: false,
    file: 'www/bin/node/app.js',
    format: 'es',
  },
	plugins,
};